<?php


/**
 * Base class that represents a query for the 'committees' table.
 *
 *
 *
 * @method EmpevalCommitteesQuery orderByUserId($order = Criteria::ASC) Order by the user_id column
 * @method EmpevalCommitteesQuery orderByBonusGoalsFormId($order = Criteria::ASC) Order by the bonus_goals_form_id column
 * @method EmpevalCommitteesQuery orderByCreated($order = Criteria::ASC) Order by the created column
 *
 * @method EmpevalCommitteesQuery groupByUserId() Group by the user_id column
 * @method EmpevalCommitteesQuery groupByBonusGoalsFormId() Group by the bonus_goals_form_id column
 * @method EmpevalCommitteesQuery groupByCreated() Group by the created column
 *
 * @method EmpevalCommitteesQuery leftJoin($relation) Adds a LEFT JOIN clause to the query
 * @method EmpevalCommitteesQuery rightJoin($relation) Adds a RIGHT JOIN clause to the query
 * @method EmpevalCommitteesQuery innerJoin($relation) Adds a INNER JOIN clause to the query
 *
 * @method EmpevalCommitteesQuery leftJoinRejections($relationAlias = null) Adds a LEFT JOIN clause to the query using the Rejections relation
 * @method EmpevalCommitteesQuery rightJoinRejections($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Rejections relation
 * @method EmpevalCommitteesQuery innerJoinRejections($relationAlias = null) Adds a INNER JOIN clause to the query using the Rejections relation
 *
 * @method EmpevalCommitteesQuery leftJoinViewRejectionsReport($relationAlias = null) Adds a LEFT JOIN clause to the query using the ViewRejectionsReport relation
 * @method EmpevalCommitteesQuery rightJoinViewRejectionsReport($relationAlias = null) Adds a RIGHT JOIN clause to the query using the ViewRejectionsReport relation
 * @method EmpevalCommitteesQuery innerJoinViewRejectionsReport($relationAlias = null) Adds a INNER JOIN clause to the query using the ViewRejectionsReport relation
 *
 * @method EmpevalCommitteesQuery leftJoinUsers($relationAlias = null) Adds a LEFT JOIN clause to the query using the Users relation
 * @method EmpevalCommitteesQuery rightJoinUsers($relationAlias = null) Adds a RIGHT JOIN clause to the query using the Users relation
 * @method EmpevalCommitteesQuery innerJoinUsers($relationAlias = null) Adds a INNER JOIN clause to the query using the Users relation
 *
 * @method EmpevalCommittees findOne(PropelPDO $con = null) Return the first EmpevalCommittees matching the query
 * @method EmpevalCommittees findOneOrCreate(PropelPDO $con = null) Return the first EmpevalCommittees matching the query, or a new EmpevalCommittees object populated from the query conditions when no match is found
 *
 * @method EmpevalCommittees findOneByUserId(int $user_id) Return the first EmpevalCommittees filtered by the user_id column
 * @method EmpevalCommittees findOneByBonusGoalsFormId(int $bonus_goals_form_id) Return the first EmpevalCommittees filtered by the bonus_goals_form_id column
 * @method EmpevalCommittees findOneByCreated(string $created) Return the first EmpevalCommittees filtered by the created column
 *
 * @method array findByUserId(int $user_id) Return EmpevalCommittees objects filtered by the user_id column
 * @method array findByBonusGoalsFormId(int $bonus_goals_form_id) Return EmpevalCommittees objects filtered by the bonus_goals_form_id column
 * @method array findByCreated(string $created) Return EmpevalCommittees objects filtered by the created column
 *
 * @package    propel.generator.empeval.om
 */
abstract class EmpevalBaseCommitteesQuery extends ModelCriteria
{
    /**
     * Initializes internal state of EmpevalBaseCommitteesQuery object.
     *
     * @param     string $dbName The dabase name
     * @param     string $modelName The phpName of a model, e.g. 'Book'
     * @param     string $modelAlias The alias for the model in this query, e.g. 'b'
     */
    public function __construct($dbName = 'vgp_empeval', $modelName = 'EmpevalCommittees', $modelAlias = null)
    {
        parent::__construct($dbName, $modelName, $modelAlias);
    }

    /**
     * Returns a new EmpevalCommitteesQuery object.
     *
     * @param     string $modelAlias The alias of a model in the query
     * @param     EmpevalCommitteesQuery|Criteria $criteria Optional Criteria to build the query from
     *
     * @return EmpevalCommitteesQuery
     */
    public static function create($modelAlias = null, $criteria = null)
    {
        if ($criteria instanceof EmpevalCommitteesQuery) {
            return $criteria;
        }
        $query = new EmpevalCommitteesQuery();
        if (null !== $modelAlias) {
            $query->setModelAlias($modelAlias);
        }
        if ($criteria instanceof Criteria) {
            $query->mergeWith($criteria);
        }

        return $query;
    }

    /**
     * Find object by primary key.
     * Propel uses the instance pool to skip the database if the object exists.
     * Go fast if the query is untouched.
     *
     * <code>
     * $obj = $c->findPk(array(12, 34), $con);
     * </code>
     *
     * @param array $key Primary key to use for the query
                         A Primary key composition: [$user_id, $bonus_goals_form_id]
     * @param     PropelPDO $con an optional connection object
     *
     * @return   EmpevalCommittees|EmpevalCommittees[]|mixed the result, formatted by the current formatter
     */
    public function findPk($key, $con = null)
    {
        if ($key === null) {
            return null;
        }
        if ((null !== ($obj = EmpevalCommitteesPeer::getInstanceFromPool(serialize(array((string) $key[0], (string) $key[1]))))) && !$this->formatter) {
            // the object is alredy in the instance pool
            return $obj;
        }
        if ($con === null) {
            $con = Propel::getConnection(EmpevalCommitteesPeer::DATABASE_NAME, Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        if ($this->formatter || $this->modelAlias || $this->with || $this->select
         || $this->selectColumns || $this->asColumns || $this->selectModifiers
         || $this->map || $this->having || $this->joins) {
            return $this->findPkComplex($key, $con);
        } else {
            return $this->findPkSimple($key, $con);
        }
    }

    /**
     * Find object by primary key using raw SQL to go fast.
     * Bypass doSelect() and the object formatter by using generated code.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return   EmpevalCommittees A model object, or null if the key is not found
     * @throws   PropelException
     */
    protected function findPkSimple($key, $con)
    {
        $sql = 'SELECT USER_ID, BONUS_GOALS_FORM_ID, CREATED FROM committees WHERE USER_ID = :p0 AND BONUS_GOALS_FORM_ID = :p1';
        try {
            $stmt = $con->prepare($sql);
            $stmt->bindValue(':p0', $key[0], PDO::PARAM_INT);
            $stmt->bindValue(':p1', $key[1], PDO::PARAM_INT);
            $stmt->execute();
        } catch (Exception $e) {
            Propel::log($e->getMessage(), Propel::LOG_ERR);
            throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
        }
        $obj = null;
        if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
            $obj = new EmpevalCommittees();
            $obj->hydrate($row);
            EmpevalCommitteesPeer::addInstanceToPool($obj, serialize(array((string) $key[0], (string) $key[1])));
        }
        $stmt->closeCursor();

        return $obj;
    }

    /**
     * Find object by primary key.
     *
     * @param     mixed $key Primary key to use for the query
     * @param     PropelPDO $con A connection object
     *
     * @return EmpevalCommittees|EmpevalCommittees[]|mixed the result, formatted by the current formatter
     */
    protected function findPkComplex($key, $con)
    {
        // As the query uses a PK condition, no limit(1) is necessary.
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKey($key)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->formatOne($stmt);
    }

    /**
     * Find objects by primary key
     * <code>
     * $objs = $c->findPks(array(array(12, 56), array(832, 123), array(123, 456)), $con);
     * </code>
     * @param     array $keys Primary keys to use for the query
     * @param     PropelPDO $con an optional connection object
     *
     * @return PropelObjectCollection|EmpevalCommittees[]|mixed the list of results, formatted by the current formatter
     */
    public function findPks($keys, $con = null)
    {
        if ($con === null) {
            $con = Propel::getConnection($this->getDbName(), Propel::CONNECTION_READ);
        }
        $this->basePreSelect($con);
        $criteria = $this->isKeepQuery() ? clone $this : $this;
        $stmt = $criteria
            ->filterByPrimaryKeys($keys)
            ->doSelect($con);

        return $criteria->getFormatter()->init($criteria)->format($stmt);
    }

    /**
     * Filter the query by primary key
     *
     * @param     mixed $key Primary key to use for the query
     *
     * @return EmpevalCommitteesQuery The current query, for fluid interface
     */
    public function filterByPrimaryKey($key)
    {
        $this->addUsingAlias(EmpevalCommitteesPeer::USER_ID, $key[0], Criteria::EQUAL);
        $this->addUsingAlias(EmpevalCommitteesPeer::BONUS_GOALS_FORM_ID, $key[1], Criteria::EQUAL);

        return $this;
    }

    /**
     * Filter the query by a list of primary keys
     *
     * @param     array $keys The list of primary key to use for the query
     *
     * @return EmpevalCommitteesQuery The current query, for fluid interface
     */
    public function filterByPrimaryKeys($keys)
    {
        if (empty($keys)) {
            return $this->add(null, '1<>1', Criteria::CUSTOM);
        }
        foreach ($keys as $key) {
            $cton0 = $this->getNewCriterion(EmpevalCommitteesPeer::USER_ID, $key[0], Criteria::EQUAL);
            $cton1 = $this->getNewCriterion(EmpevalCommitteesPeer::BONUS_GOALS_FORM_ID, $key[1], Criteria::EQUAL);
            $cton0->addAnd($cton1);
            $this->addOr($cton0);
        }

        return $this;
    }

    /**
     * Filter the query on the user_id column
     *
     * Example usage:
     * <code>
     * $query->filterByUserId(1234); // WHERE user_id = 1234
     * $query->filterByUserId(array(12, 34)); // WHERE user_id IN (12, 34)
     * $query->filterByUserId(array('min' => 12)); // WHERE user_id > 12
     * </code>
     *
     * @see       filterByUsers()
     *
     * @param     mixed $userId The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return EmpevalCommitteesQuery The current query, for fluid interface
     */
    public function filterByUserId($userId = null, $comparison = null)
    {
        if (is_array($userId) && null === $comparison) {
            $comparison = Criteria::IN;
        }

        return $this->addUsingAlias(EmpevalCommitteesPeer::USER_ID, $userId, $comparison);
    }

    /**
     * Filter the query on the bonus_goals_form_id column
     *
     * Example usage:
     * <code>
     * $query->filterByBonusGoalsFormId(1234); // WHERE bonus_goals_form_id = 1234
     * $query->filterByBonusGoalsFormId(array(12, 34)); // WHERE bonus_goals_form_id IN (12, 34)
     * $query->filterByBonusGoalsFormId(array('min' => 12)); // WHERE bonus_goals_form_id > 12
     * </code>
     *
     * @see       filterByRejections()
     *
     * @see       filterByViewRejectionsReport()
     *
     * @param     mixed $bonusGoalsFormId The value to use as filter.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return EmpevalCommitteesQuery The current query, for fluid interface
     */
    public function filterByBonusGoalsFormId($bonusGoalsFormId = null, $comparison = null)
    {
        if (is_array($bonusGoalsFormId) && null === $comparison) {
            $comparison = Criteria::IN;
        }

        return $this->addUsingAlias(EmpevalCommitteesPeer::BONUS_GOALS_FORM_ID, $bonusGoalsFormId, $comparison);
    }

    /**
     * Filter the query on the created column
     *
     * Example usage:
     * <code>
     * $query->filterByCreated('2011-03-14'); // WHERE created = '2011-03-14'
     * $query->filterByCreated('now'); // WHERE created = '2011-03-14'
     * $query->filterByCreated(array('max' => 'yesterday')); // WHERE created > '2011-03-13'
     * </code>
     *
     * @param     mixed $created The value to use as filter.
     *              Values can be integers (unix timestamps), DateTime objects, or strings.
     *              Empty strings are treated as NULL.
     *              Use scalar values for equality.
     *              Use array values for in_array() equivalent.
     *              Use associative array('min' => $minValue, 'max' => $maxValue) for intervals.
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return EmpevalCommitteesQuery The current query, for fluid interface
     */
    public function filterByCreated($created = null, $comparison = null)
    {
        if (is_array($created)) {
            $useMinMax = false;
            if (isset($created['min'])) {
                $this->addUsingAlias(EmpevalCommitteesPeer::CREATED, $created['min'], Criteria::GREATER_EQUAL);
                $useMinMax = true;
            }
            if (isset($created['max'])) {
                $this->addUsingAlias(EmpevalCommitteesPeer::CREATED, $created['max'], Criteria::LESS_EQUAL);
                $useMinMax = true;
            }
            if ($useMinMax) {
                return $this;
            }
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }
        }

        return $this->addUsingAlias(EmpevalCommitteesPeer::CREATED, $created, $comparison);
    }

    /**
     * Filter the query by a related EmpevalRejections object
     *
     * @param   EmpevalRejections|PropelObjectCollection $rejections The related object(s) to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   EmpevalCommitteesQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByRejections($rejections, $comparison = null)
    {
        if ($rejections instanceof EmpevalRejections) {
            return $this
                ->addUsingAlias(EmpevalCommitteesPeer::BONUS_GOALS_FORM_ID, $rejections->getBonusGoalsFormId(), $comparison);
        } elseif ($rejections instanceof PropelObjectCollection) {
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }

            return $this
                ->addUsingAlias(EmpevalCommitteesPeer::BONUS_GOALS_FORM_ID, $rejections->toKeyValue('PrimaryKey', 'BonusGoalsFormId'), $comparison);
        } else {
            throw new PropelException('filterByRejections() only accepts arguments of type EmpevalRejections or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the Rejections relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return EmpevalCommitteesQuery The current query, for fluid interface
     */
    public function joinRejections($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('Rejections');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'Rejections');
        }

        return $this;
    }

    /**
     * Use the Rejections relation Rejections object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   EmpevalRejectionsQuery A secondary query class using the current class as primary query
     */
    public function useRejectionsQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinRejections($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'Rejections', 'EmpevalRejectionsQuery');
    }

    /**
     * Filter the query by a related EmpevalViewRejectionsReport object
     *
     * @param   EmpevalViewRejectionsReport|PropelObjectCollection $viewRejectionsReport The related object(s) to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   EmpevalCommitteesQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByViewRejectionsReport($viewRejectionsReport, $comparison = null)
    {
        if ($viewRejectionsReport instanceof EmpevalViewRejectionsReport) {
            return $this
                ->addUsingAlias(EmpevalCommitteesPeer::BONUS_GOALS_FORM_ID, $viewRejectionsReport->getBonusGoalsFormId(), $comparison);
        } elseif ($viewRejectionsReport instanceof PropelObjectCollection) {
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }

            return $this
                ->addUsingAlias(EmpevalCommitteesPeer::BONUS_GOALS_FORM_ID, $viewRejectionsReport->toKeyValue('PrimaryKey', 'BonusGoalsFormId'), $comparison);
        } else {
            throw new PropelException('filterByViewRejectionsReport() only accepts arguments of type EmpevalViewRejectionsReport or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the ViewRejectionsReport relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return EmpevalCommitteesQuery The current query, for fluid interface
     */
    public function joinViewRejectionsReport($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('ViewRejectionsReport');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'ViewRejectionsReport');
        }

        return $this;
    }

    /**
     * Use the ViewRejectionsReport relation ViewRejectionsReport object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   EmpevalViewRejectionsReportQuery A secondary query class using the current class as primary query
     */
    public function useViewRejectionsReportQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinViewRejectionsReport($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'ViewRejectionsReport', 'EmpevalViewRejectionsReportQuery');
    }

    /**
     * Filter the query by a related EmpevalUsers object
     *
     * @param   EmpevalUsers|PropelObjectCollection $users The related object(s) to use as filter
     * @param     string $comparison Operator to use for the column comparison, defaults to Criteria::EQUAL
     *
     * @return   EmpevalCommitteesQuery The current query, for fluid interface
     * @throws   PropelException - if the provided filter is invalid.
     */
    public function filterByUsers($users, $comparison = null)
    {
        if ($users instanceof EmpevalUsers) {
            return $this
                ->addUsingAlias(EmpevalCommitteesPeer::USER_ID, $users->getId(), $comparison);
        } elseif ($users instanceof PropelObjectCollection) {
            if (null === $comparison) {
                $comparison = Criteria::IN;
            }

            return $this
                ->addUsingAlias(EmpevalCommitteesPeer::USER_ID, $users->toKeyValue('PrimaryKey', 'Id'), $comparison);
        } else {
            throw new PropelException('filterByUsers() only accepts arguments of type EmpevalUsers or PropelCollection');
        }
    }

    /**
     * Adds a JOIN clause to the query using the Users relation
     *
     * @param     string $relationAlias optional alias for the relation
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return EmpevalCommitteesQuery The current query, for fluid interface
     */
    public function joinUsers($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        $tableMap = $this->getTableMap();
        $relationMap = $tableMap->getRelation('Users');

        // create a ModelJoin object for this join
        $join = new ModelJoin();
        $join->setJoinType($joinType);
        $join->setRelationMap($relationMap, $this->useAliasInSQL ? $this->getModelAlias() : null, $relationAlias);
        if ($previousJoin = $this->getPreviousJoin()) {
            $join->setPreviousJoin($previousJoin);
        }

        // add the ModelJoin to the current object
        if ($relationAlias) {
            $this->addAlias($relationAlias, $relationMap->getRightTable()->getName());
            $this->addJoinObject($join, $relationAlias);
        } else {
            $this->addJoinObject($join, 'Users');
        }

        return $this;
    }

    /**
     * Use the Users relation Users object
     *
     * @see       useQuery()
     *
     * @param     string $relationAlias optional alias for the relation,
     *                                   to be used as main alias in the secondary query
     * @param     string $joinType Accepted values are null, 'left join', 'right join', 'inner join'
     *
     * @return   EmpevalUsersQuery A secondary query class using the current class as primary query
     */
    public function useUsersQuery($relationAlias = null, $joinType = Criteria::INNER_JOIN)
    {
        return $this
            ->joinUsers($relationAlias, $joinType)
            ->useQuery($relationAlias ? $relationAlias : 'Users', 'EmpevalUsersQuery');
    }

    /**
     * Exclude object from result
     *
     * @param   EmpevalCommittees $committees Object to remove from the list of results
     *
     * @return EmpevalCommitteesQuery The current query, for fluid interface
     */
    public function prune($committees = null)
    {
        if ($committees) {
            $this->addCond('pruneCond0', $this->getAliasedColName(EmpevalCommitteesPeer::USER_ID), $committees->getUserId(), Criteria::NOT_EQUAL);
            $this->addCond('pruneCond1', $this->getAliasedColName(EmpevalCommitteesPeer::BONUS_GOALS_FORM_ID), $committees->getBonusGoalsFormId(), Criteria::NOT_EQUAL);
            $this->combine(array('pruneCond0', 'pruneCond1'), Criteria::LOGICAL_OR);
        }

        return $this;
    }

}
